class Solution {
    public:
        int is_existent[200][200] = {0};
        void solve(vector<vector<char>>& board) {
            int n = board.size(),m=board[0].size();
            for(int j = 0 ; j < m ; j++){
                if(board[0][j] == 'O')  dfs(board,0,j);
                if(board[n-1][j] == 'O') dfs(board,n-1,j);
            }
            for(int i = 0 ; i < n ; i++){
                if(board[i][0] == 'O')  dfs(board,i,0);
                if(board[i][m-1] == 'O') dfs(board,i,m-1);
            }
            for(int i = 0 ; i < n ; i++){
                for(int j = 0 ; j < m ; j++){
                    if(board[i][j] == 'O') board[i][j] = 'X';
                    if(board[i][j] == 'T')  board[i][j] = 'O';
                }
            }
        }
        int indexx[4] = {0,0,-1,1};
        int indexy[4] = {-1,1,0,0};
        void dfs(vector<vector<char>>& board,int i , int j){
            int n = board.size(),m=board[0].size();
            if(i >= 0 && i < n && j >= 0 && j < m && board[i][j] == 'O' && is_existent[i][j] == 0){
                is_existent[i][j] = 1;
                board[i][j] = 'T';
                for(int k = 0 ; k < 4 ;k++){
                    int row = i+indexx[k];
                    int col = j+indexy[k];
                    dfs(board,row,col);
                }
            }
        }
    };